package com.wandian.texas.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;

import com.wandian.util.DESUtil;
import com.wandian.util.Log;

/**
 * 一个具体的连接实体
 * 
 * @author long
 * @Create 2012-10-12 上午10:22:33
 * @QQ 108232706
 * @version 1.0
 * @description DBBase
 */
public class DBBase {
	public String dbName;
	private final Connection connection;

	public DBBase(Properties dbProps, String databaseName) throws Throwable {
		dbName = databaseName;
		String url = dbProps.getProperty(dbName + ".url");
		String user = DESUtil.decrypt(dbProps.getProperty(dbName + ".user"));
		String password = DESUtil.decrypt(dbProps.getProperty(dbName + ".password"));
		String maxconn = dbProps.getProperty(dbName + ".maxconn", "5");
		String driver = dbProps.getProperty(dbName + ".driver");
		try {
			Class.forName(driver);
		} catch (ClassNotFoundException e) {
			Log.error("初始化数据库连接池错误", e);
			throw new Throwable("初始化数据库连接池错误" + e);
		}
		// 创建Connection
		connection = DriverManager.getConnection(url, user, password);
	}

	Connection getConnection() {
		return connection;
	}
}
